package com.house.system.controller;

import com.house.common.utils.PageUtils;
import com.house.common.utils.R;
import com.house.system.entity.TbArea;
import com.house.system.entity.TbSchool;
import com.house.system.service.SchoolService;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/school")
public class SchoolController {

    private  final SchoolService schoolService;

    public SchoolController(SchoolService schoolService) {
        this.schoolService = schoolService;
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = schoolService.queryPage(params);
        return R.ok().put("page", page);
    }

    @RequestMapping("/findlist/{aid}")
    public R findlist(@PathVariable("aid") Integer cid){
        List<TbArea> tbAreaList = schoolService.findlist(cid);
        return  R.ok().put("tbarea",tbAreaList);
    }


    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody TbSchool tbSchool){
        schoolService.saves(tbSchool);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody TbSchool tbSchool){
        schoolService.updateByIds(tbSchool);


        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete/{id}")
    public R delete(@PathVariable("id") Integer id){
        schoolService.removeByIds(id);

        return R.ok();
    }


}
